/**
 * Created with Intellij IDEA
 * Description
 * User:ASUS
 * Date:2024-05-15
 * Time:20:35
 */
// Animal类
abstract class Animal {
    protected String type;
    protected int legs;

    protected Animal(String type, int legs) {
        this.type = type;
        this.legs = legs;
    }

    abstract void eat();

    void walk() {
        System.out.println(type + " 用 " + legs + " 条腿走路");
    }
}

// Spider类
class Spider extends Animal {
    Spider() {
        super("spider", 8);
    }

    void eat() {
        System.out.println("spider eating");
    }
}

// Pet接口
interface Pet {
    void setName(String name);
    String getName();
    void play();
}

// Cat类
class Cat extends Animal implements Pet {
    private String name;

    Cat(String name) {
        super("cat", 4);
        this.name = name;
    }

    Cat() {
        this("");
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void play() {
        System.out.println("Cat is playing");
    }

    public void eat() {
        System.out.println(name + " eating");
    }
}
// Dog类（由于要求中是Cat，但为了完整性我添加了Dog类）
class Dog extends Animal implements Pet {
    private String name;

    Dog(String name) {
        super("dog", 4);
        this.name = name;
    }
    Dog() {
        this("");
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void play() {
        System.out.println("Dog is playing");
    }

    public void eat() {
        System.out.println(name + " eating");
    }
}
// Demo类
public class Demo {
    public static void main(String[] args) {
        Spider spider = new Spider();
        spider.walk(); // 使用 walk 方法，因为 Spider 是 Animal 的子类

        Cat cat = new Cat("Kitty");
        System.out.println("小猫的名字叫：" + cat.getName());
        cat.walk(); // 同样使用 walk 方法
        cat.play();
        cat.eat();

        Dog dog = new Dog("Snoopy");
        dog.walk(); // 使用 walk 方法
        dog.play();
        dog.eat();
    }

    public void walk(Animal animal) { // 接受 Animal 类型参数
        animal.walk();
    }

    public void playWith(Pet pet) { // 接受 Pet 类型参数
        System.out.println("宠物 " + pet.getName() + " 正在玩耍...");
        pet.play();
    }
}
